package cn.edu.jxau.core.aop;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.List;

/**
 * Desc:
 * ------------------------------------
 * Author:fulei04@meituan.com
 * Date:2017/12/20
 * Time:下午2:57
 */
public class ProxyFactory {

    public static <T> T createProxy(Class<?> targetClass, List<Proxy> proxyList) {
        return (T) Enhancer.create(targetClass,new MethodInterceptor() {
            @Override
            public Object intercept(Object target, Method targetMethod, Object[] methodParams,
                                    MethodProxy methodProxy) throws Throwable {
                return new ProxyChain(targetClass,target,targetMethod,methodProxy,methodParams,proxyList).doProxyChain();
            }
        });
    }
}
